
import time,resource,math,os
import random

INF = 10e10

def length(worker:list,task:list)->float:#求两个点的长度
    distance = (worker[2]-task[2])**2+(worker[3]-task[2])**2
#     print(distance)
    distance = pow(distance,1/2)
    return distance
#     print(distance)

def length2(worker:list,task:list)->float:#求两个点的长度,不开方的
    distance = (worker[2]-task[2])**2+(worker[3]-task[3])**2
    return distance

def satisfyLoc(worker:list,task:list)->bool:#验证任务与工作者之间是否符合活动范围内
    if length2(worker,task) > worker[4]*worker[4]:
        return False
    return True

def satifyTime(worker:list,task:list)->bool:
    if (worker[0] < task[4] and task[0] < worker[6]) is False:
        return False
    return True

def satify(worker:list,task:list)->bool:
    if satifyTime(worker,task) and satisfyLoc(worker,task):
        return True
    return False
    

def calcCost(worker:list,task:list)->float:
    if satisfyLoc(worker,task) and satifyTime(worker,task):
        return worker[7]*task[5]
    else:
        return 0.0

def dcmp(a:float,b:float)->bool:
    return math.isclose(a,b,rel_tol=1e-6)
def dcmp(a:float)->bool:
    return abs(a)<1e-6

class KM:
    def __init__(self,curTime,workerlist,tasklist):
        self.curTime = curTime
        self.workerlist = workerlist
        self.tasklist = tasklist
        self.wsize = len(workerlist)
        self.tsize = len(tasklist)
        self.slack = INF
        self.slacks = []
        self.weight = []
        self.lx = []
        self.ly = []
        self.xy = []
        self.yx = []
        self.visitx = []
        self.visity = []
        
        
    def build(self,flag):
        if flag:#一般情况需要左边的节点少于右边节点，因为我选择右边节点开始遍历，如果右边节点多余左边节点会出现完全匹配时候无法退出dfs
            self.lx = [0.0 for i in range(self.wsize)]
            self.ly = [0.0 for i in range(self.tsize)]
            self.xy = [-1 for i in range(self.wsize)]
            self.yx = [-1 for i in range(self.tsize)]
            self.visitx = [False for i in range(self.wsize)]
            self.visity = [False for i in range(self.tsize)]
            for x in range(self.wsize):
                temp = []
                for y in range(self.tsize):
                    u = calcCost(self.workerlist[x],self.tasklist[y])
                    temp.append(u)
                    self.lx[x] = max(u,self.lx[x])
                self.weight.append(temp)
                    
        else:
            self.lx = [0.0 for i in range(self.tsize)]
            self.ly = [0.0 for i in range(self.wsize)]
            self.xy = [-1 for i in range(self.tsize)]
            self.yx = [-1 for i in range(self.wsize)]
            self.visitx = [False for i in range(self.tsize)]
            self.visity = [False for i in range(self.wsize)]
            for x in range(self.tsize):
                temp = []
                for y in range(self.wsize):
                    u = calcCost(self.workerlist[y],self.tasklist[x])
                    temp.append(u)
                    self.lx[x] = max(u,self.lx[x])
                self.weight.append(temp)
      
    def success(self,flag):
        #识别并删除成功匹配的
        utility = 0.0
        removeWorkers = [False for i in range(self.wsize)]
        removeTasks = [False for i in range(self.tsize)]
        if flag:
            for w,t in enumerate(self.xy):
                if t!=-1:
                    u = self.weight[w][t]
                    k = self.workerlist[w][8]
                    threshold = math.exp(k)
                    if u > 0.0 and u >= threshold:
                        utility +=u
                        removeWorkers[w]=True
                        removeTasks[t]=True
        else:
            for t,w in enumerate(self.xy):
                if w!=-1:
                    u = self.weight[t][w]
                    k = self.workerlist[w][8]
                    threshold = math.exp(k)
                    if u > 0.0 and u >= threshold:
                        utility +=u
                        removeWorkers[w]=True
                        removeTasks[t]=True
        #识别未匹配成功的，并删除超时的众包对象
        wt = []
        tt = []
        for w,flag in enumerate(removeWorkers):
            worker = self.workerlist[w]
            if flag==False and worker[6] >= self.curTime:
                if worker[8] > 0:
                    worker[8] -= 1
                wt.append(worker)
        
        for t,flag in enumerate(removeTasks):
            task = self.tasklist[t]
            if flag==False and task[4] >= self.curTime:
                tt.append(task)

        return [utility,wt,tt]
    
    def dfs(self,x:int)->bool:
        self.visitx[x] = True
        for y,flag in enumerate(self.visity):
            if flag:
                continue
            temp = self.lx[x] + self.ly[y] - self.weight[x][y]
#             temp = self.lx[x] + self.ly[y] - calcCost(self.workerlist[x],self.tasklist[y])
            if dcmp(temp):
                self.visity[y] = True
                if self.yx[y] == -1 or self.dfs(self.yx[y]):
                    self.xy[x] = y
                    self.yx[y] = x
                    return True
            else:
                self.slack = min(self.slack,temp)
                self.slacks[y] = min(self.slacks[y],temp)###
        return False 
    
    def match(self):
        ans = [0,[],[]]
        wtflag = False
        
        if self.wsize <= self.tsize:#工作者作为左边节点
            if self.wsize == 0 or self.tsize == 0:
                ans[1] = self.workerlist
                ans[2] = self.tasklist
                return ans
            wtflag = True
            self.build(wtflag)
            for x in range(self.wsize): 
                self.slacks = [INF for i in range(self.tsize)]###
                while True:
                    self.visitx = [False for i in range(self.wsize)]
                    self.visity = [False for i in range(self.tsize)]
                    self.slack = INF
                    #wsize<tsize
                    if self.dfs(x):
                        break

                    #更新访问过的节点, 因为self.wsize <= self.tsize，这里还可以优化加速
                    mm = INF###
                    for i,flag in enumerate(self.visity):###
                        if flag == False:###
                            mm = min(self.slacks[i],mm)###
                    for i,flag in enumerate(self.visitx):
                        if flag:
#                             self.lx[i] -= self.slack
                            self.lx[i] -= mm###
                    for i,flag in enumerate(self.visity):
                        if flag:
#                             self.ly[i] += self.slack
                            self.ly[i] += mm###
                        else:###
                            self.slacks[i] -= mm###
            ans = self.success(wtflag)#工作者左边
            return ans

        else:#任务作为左边节点
            if self.wsize == 0 or self.tsize == 0:
                ans[1] = self.workerlist
                ans[2] = self.tasklist
                return ans
            wtflag = False
            self.build(wtflag)
            for x in range(self.tsize):
                self.slacks = [INF for i in range(self.wsize)]###
                while True:
                    self.visitx = [False for i in range(self.tsize)]
                    self.visity = [False for i in range(self.wsize)]
                    self.slack = INF
                    if self.dfs(x):
                        break
                    #更新访问过的节点, 因为self.wsize > self.tsize，这里还可以优化加速
                    mm = INF###
                    for i,flag in enumerate(self.visity):###
                        if flag == False:###
                            mm = min(self.slacks[i],mm)###
                            
                    for i,flag in enumerate(self.visitx):
                        if flag:
                            self.lx[i] -= self.slack
#                             self.lx[i] -= mm###
                    for i,flag in enumerate(self.visity):
                        if flag:
                            self.ly[i] += self.slack
#                             self.ly[i] += mm###
                        else:###
                            self.slacks[i] -= mm###
            ans = self.success(wtflag)#任务左边
            return ans
#选择超过某一个固定阈值的高质量工作者
def waterFilter(workerList,taskList,curTime):
    ans = 0
    successNum = 0
    nMatchW = []
    for windex,worker in enumerate(workerList):
        k = worker[8]
        threshold = math.exp(k)
        maxCost = 0.0
        tmid = -1
        for tindex,task in enumerate(taskList):
            tempCost = calcCost(worker,task)
            if tempCost >= threshold and tempCost > maxCost and worker[6] >= curTime and task[4] >= curTime:
                maxCost = tempCost
                tmid = tindex
        if tmid != -1:#匹配成功
            taskList.pop(tmid)
            ans += maxCost
            successNum += 1
        else:
            if worker[8] > 0:
                worker[8] -= 1
            if worker[6] >= curTime:
                nMatchW.append(worker)
#             nMatchW.append(worker)

    return nMatchW,ans,successNum
                
    

workers = []
tasks = []
queue = []
def readData(fileName):
    with open(fileName,'r') as f:
        data = f.readlines()
        first = data[0].strip("\n").split(" ")
        workerNum = int(first[0])
        taskNum = int(first[1])
        utilityMax = int(first[2])
        theta = round(math.log(utilityMax+1.0),0)
        theta = int(theta)
        for i in range(1,len(data)):
            node = data[i].strip("\n").split(" ")
            if node[1]=='w':
                node[0]=int(node[0])#到达时间
                node[2]=float(node[2])#纬度
                node[3]=float(node[3])#经度
                node[4]=float(node[4])#半径
                node[5]=int(node[5])#能力
                node[6]=int(node[6])+node[0]#停留的时间
                node[7]=float(node[7])#接受率
                if len(node) < 9:#最后一个用来记录等待多久匹配
                    node.append(theta-2)
                else:
                    node[8] = theta-2
                workers.append(node)
            else:
                node[0]=int(node[0])#到达时间
                node[2]=float(node[2])#纬度
                node[3]=float(node[3])#经度
                node[4]=int(node[4])+node[0]#停留的时间
                node[5]=float(node[5])#支付的报酬
                if len(node) < 7:
                    node.append(0)
                else:
                    node[6] = 0
                tasks.append(node)
            queue.append(node)
    return workerNum,taskNum,utilityMax


QMAX = 100 #Q表横纵的最大值
ACTION = 8#智能体的动作
Qtable = []
ALPHA = 0.01 #学习率
GAMMA = 0.98 #折扣因子
EPSILON = 0.01#探索的概率

def maxAction(aList:list):
    maxValue = -1
    position = 0
    for index,value in enumerate(aList):
        if value >= maxValue:
            position = index
            maxValue = value
    return position
    
def initQ():
    for i in range(QMAX):
        Qtable.append([])
        for j in range(QMAX):
            Qtable[i].append([])
            for k in range(ACTION):
                initData = 0.000001*random.randint(0,100)
                Qtable[i][j].append(initData)

def Qlearning():
    initQ()
    mworkers = []
    mtasks = []
    arrWorkers = []
    arrTasks = []
    curTime = 0
    lastTime = -1
    #当前状态
    lastWnu = 0
    lastTnu = 0
    #下一个状态
    wnu = 0
    tnu = 0
    curA = 0
    lastA = 0
    reward = 0
    utility = 0.0
    matchNum = 0
    queueW = [[] for i in range(ACTION)]
    queueT = [[] for i in range(ACTION)]
    for item in queue:
        curTime = item[0]
        crowType = item[1]
        if crowType == "w":
            cap = item[5]
            for w in range(cap):
                arrWorkers.append(item)
        else:
            arrTasks.append(item)
        if lastTime != curTime:
            probability = random.random()
            if probability < EPSILON:
                curA = random.randint(0,ACTION-1)#随机选所有动作的一个
            else:
                curA = maxAction(Qtable[lastWnu][lastTnu])#选择当前状态
            savePosition = (curTime+curA)%ACTION
            for ws in arrWorkers:
                queueW[savePosition].append(ws)
            for ts in arrTasks:
                queueT[savePosition].append(ts)
                
            matchPosition = curTime%ACTION
            for ws in queueW[matchPosition]:
                mworkers.append(ws)
            for ts in queueT[matchPosition]:
                mtasks.append(ts)
            queueW[matchPosition] = []
            queueT[matchPosition] = []
            
            mworkers,reward,ntemp = waterFilter(mworkers,mtasks,curTime)
            
#             assignment = KM(curTime,mworkers,mtasks)
#             reward,mworkers,mtasks = assignment.match()
            utility += reward
            matchNum += ntemp
            
            wnu = len(mworkers)
            tnu = len(mtasks)
             
            for ws in queueW:
                wnu += len(ws)
            for ts in queueT:
                tnu += len(ts)
            if wnu >= QMAX:
                wnu = wnu%QMAX
            if tnu >= QMAX:
                tnu = tnu%QMAX
                
            Qtable[lastWnu][lastTnu][lastA] += ALPHA*(reward+GAMMA*max(Qtable[wnu][tnu])-Qtable[lastWnu][lastTnu][lastA])
            
            lastA = curA
            lastWnu = wnu
            lastTnu = tnu
            lastTime = curTime
            arrWorkers.clear()
            arrTasks.clear()
    return utility,matchNum


def solve():
    memory = resource.getrusage(resource.RUSAGE_SELF)
    avgUtility = 0.0
    avgTime = 0
    avgMemory = 0
    avgMatchNu = 0
    startTime = time.perf_counter()
    avgUtility,avgMatchNu = Qlearning()
    endTime = time.perf_counter()
    avgTime = endTime - startTime
    avgMemory = memory.ru_maxrss
    # print(avgUtility,avgTime,avgMemory,avgMatchNu)
    return [avgUtility,avgTime,avgMemory,avgMatchNu]

def varyWorkers(testNUm):#测试变化的工作者，其余变量保持不变
    fin = open("./result/synthetic/data/varyworkers.txt",'a+',encoding='utf-8')
    for w in  [100, 200, 500, 1000, 5000]:
        fileName = f"./dataset/synthetic/{w}_2500_1_2.0_0.5_6_10/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")
        
    #文件关闭
    fin.close()

def varyTasks(testNUm):#测试变化的工作者
    fin = open("./result/synthetic/data/varytasks.txt",'a+',encoding='utf-8')
    for t in   [500, 1000, 2500, 5000, 10000]:
        fileName = f"./dataset/synthetic/500_{t}_1_2.0_0.5_6_10/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")
        
    #文件关闭
    fin.close()

def varyCw(testNUm):#测试工作者能力变化的影响
    fin = open("./result/synthetic/data/varycw.txt",'a+',encoding='utf-8')
    for cw in [1, 2, 3, 4, 5]:
        fileName = f"./dataset/synthetic/500_2500_{cw}_2.0_0.5_6_10/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")
        
    #文件关闭
    fin.close()

def varyRw(testNUm):#测试工作者半径变化的影响
    fin = open("./result/synthetic/data/varyrw.txt",'a+',encoding='utf-8')
    for rw in [1.0, 1.5, 2.0, 2.5, 3.0]:
        fileName = f"./dataset/synthetic/500_2500_1_{rw}_0.5_6_10/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")
        
    #文件关闭
    fin.close()

def varyDw(testNUm):#工作者接受率变化的影响
    fin = open("./result/synthetic/data/varydw.txt",'a+',encoding='utf-8')
    for dw in [0.1, 0.3, 0.5, 0.7, 0.9]:
        fileName = f"./dataset/synthetic/500_2500_1_2.0_{dw}_6_10/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def varyDdl(testNUm):#截至时间变化的影响
    fin = open("./result/synthetic/data/varyddl.txt",'a+',encoding='utf-8')
    for ddl in [2, 4, 6, 8, 10]:
        fileName = f"./dataset/synthetic/500_2500_1_2.0_0.5_{ddl}_10/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def varyPtsNormal(testNUm):#正态分布任务支付大小变化的影响
    fin = open("./result/synthetic/data/varyptsnormal.txt",'a+',encoding='utf-8')
    for pt in [2, 5, 10, 15, 20]:
        fileName = f"./dataset/synthetic/500_2500_1_2.0_0.5_6_{pt}/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def varyPtsExponentail(testNUm):#指数分布任务支付大小变化的影响
    fin = open("./result/synthetic/data/varyptsexponentail.txt",'a+',encoding='utf-8')
    for pt in [2, 5, 10, 15, 20]:
        fileName = f"./dataset/synthetic/500_2500_1_2.0_0.5_6_{pt+100}/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def varyPtsUniform(testNUm):#任务支付大小变化的影响
    fin = open("./result/synthetic/data/varyptsuniform.txt",'a+',encoding='utf-8')
    for pt in [2, 5, 10, 15, 20]:
        fileName = f"./dataset/synthetic/500_2500_1_2.0_0.5_6_{pt+1000}/data_00.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            # workers.clear()
            # tasks.clear()
            # queue.clear()
            # utilityMax = readData(fileName)
            for n in range(testNUm):#测试次数
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def scalability(testNUm):
    fin = open("./result/synthetic/data/scalability.txt",'a+',encoding='utf-8')
    for s in range(1,11):
        w = s*10**3
        t = s*10**4
        fileName = f"./dataset/synthetic/{w}_{t}_1_2.0_0.5_6_10/data_00.txt"
        # print(fileName)
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            workers.clear()
            tasks.clear()
            queue.clear()
            readData(fileName)
            for n in range(testNUm):#测试次数
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def EverySenderCw(testNUm):#真实数据集
    fin = open("./result/real/data/varyEverysenderCw.txt",'a+',encoding='utf-8')
    for cap in [1,2,3,4,5,6,7,8,9,10]:
        fileName = f"./dataset/real/EverySender_cap{cap}/data_00_time.txt"
        ansList = [0,0,0,0]
        if os.path.exists(fileName):
            workers.clear()
            tasks.clear()
            queue.clear()
            readData(fileName)
            for n in range(testNUm):#测试次数
                ans=solve()
                for ansi in range(4):
                    ansList[ansi] += ans[ansi]
            writeStr = "QLWF(ours)"
            for result in ansList:
                temp = result/testNUm
                print(temp,end=' ')
                writeStr +=" "+str(temp)
            print()
            writeStr += "\n"
            fin.write(writeStr)
        else:
            print(fileName,"文件不存在")

def  gMissionCw(testNUm):
        fin = open("./result/real/data/varygMissionCw.txt",'a+',encoding='utf-8')
        for cap in [1,2,3,4,5,6,7,8,9,10]:
            fileName = f"./dataset/real/gMission_cap{cap}/data_00_time.txt"
            ansList = [0,0,0,0]
            if os.path.exists(fileName):
                workers.clear()
                tasks.clear()
                queue.clear()
                readData(fileName)
                for n in range(testNUm):#测试次数
                    ans=solve()
                    for ansi in range(4):
                        ansList[ansi] += ans[ansi]
                writeStr = "QLWF(ours)"
                for result in ansList:
                    temp = result/testNUm
                    print(temp,end=' ')
                    writeStr +=" "+str(temp)
                print()
                writeStr += "\n"
                fin.write(writeStr)
            else:
                print(fileName,"文件不存在")

if __name__ =="__main__":
    testNUm = 10
    varyWorkers(testNUm)
    varyTasks(testNUm)
    varyCw(testNUm)
    varyRw(testNUm)
    varyDw(testNUm)
    varyDdl(testNUm)

    varyPtsNormal(testNUm)
    varyPtsExponentail(testNUm)
    varyPtsUniform(testNUm)
    scalability(testNUm)
    EverySenderCw(testNUm)
    gMissionCw(testNUm)